package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class KeyUserFetchWindow extends JDialog {
	private static final long serialVersionUID = 1L;
	
	private JTextField userInput;
	private JButton button1;
	private JButton button2;
	private JLabel fetching = new JLabel();

	
	public KeyUserFetchWindow(String title, ActionListener actList) {
		super();
		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		JPanel userPane = new JPanel();
		JLabel labelPane = new JLabel("User name:  ");
		fetching.setVisible(false);
		userInput = new JTextField();
		userInput.setPreferredSize(new Dimension(150, 25));
		userPane.add(labelPane);
		userPane.add(userInput);
		JPanel buttonPane = new JPanel();
		button1 = new JButton("Outlier metric");
		button2 = new JButton("Std. Dev. metric");
		button1.addActionListener(actList);
		button2.addActionListener(actList);
		buttonPane.add(button1);
		buttonPane.add(button2);
		
		getContentPane().add(userPane, BorderLayout.NORTH);
		getContentPane().add(buttonPane, BorderLayout.CENTER);
		getContentPane().add(fetching, BorderLayout.SOUTH);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		getRootPane().setDefaultButton(button1);
		setSize(300, 110);
		setLocationRelativeTo(null);
		setResizable(false);
		setTitle(title);
		setVisible(true);
	}
	
	public String getUser() {
		return userInput.getText();
	}
	
	public JButton getOutlierButton() {
		return button1;
	}
	
	public JButton getStdDevButton() {
		return button2;
	}
	
	public void isFetchingVisibleWithText(Boolean b, String text) {
		fetching.setText(text);
		fetching.setVisible(b);
	}
	
	public void areButtonsVisible(Boolean b) {
		button1.setVisible(b);
		button2.setVisible(b);
	}
	
	public void isUserInputEditable(Boolean b) {
		userInput.setEditable(b);
	}
}